package com.wenxixuanwu.fruitstore.controller;

import com.wenxixuanwu.fruitstore.entity.Product;
import com.wenxixuanwu.fruitstore.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductMapper productMapper;

    @RequestMapping("/select")
    private List<Product> select(Integer cId){
        List<Product> list = productMapper.select(cId);
        return list;
    }
    /**
     * 主页销量排行榜查询
     * @return list表示排行榜的水果信息
     */
    @RequestMapping("/selectBySaleCount")
    public List<Product> selectBySaleCount(){
        List<Product> list = productMapper.selectBySaleCount();
        Product product = new Product();
        for (int i=0;i<list.size();i++){
            product = list.get(i);
            product.setId(i+1);
            list.set(i,product);
        }
        return list;
    }
}
